// 邻接表  Adjacency lIST
#include <stdio.h>
#include <stdlib.h>
#define MAX 50
#define INFINITY 9999
typedef struct ArcNode
{
    int node_num;
    struct ArcNode *next;
};
typedef struct Node
{
    int data, weight;
    ArcNode *frist;
};
typedef struct ALGraph
{
    int node_num;
    int arc_num;
    Node AdjList[MAX];
};

void create_G(ALGraph &G)
{
    int martix[5][5] = {{0, 1, 1, 1, 1},
                        {1, 0, INFINITY, 1, INFINITY},
                        {1, INFINITY, 0, 1, INFINITY},
                        {1, 1, 1, 0, 1},
                        {1, INFINITY, INFINITY, 1, 0}};
    G.node_num = 5;
    G.arc_num = 7;
    for (int i = 0; i < 5; i++)
    {
        G.AdjList[i].weight = 0;
        G.AdjList[i].data = i + 1;
        G.AdjList[i].frist = NULL;
    }
    for (int i = 0; i < G.node_num; i++)
    {
        for (int j = 0; j < G.node_num; j++)
        {
            if (martix[i][j] != 0 && martix[i][j] != INFINITY)
            {
                G.AdjList[i].weight = martix[i][j];
                ArcNode *t = G.AdjList[i].frist;
                ArcNode *p = (ArcNode *)malloc(sizeof(ArcNode));
                p->node_num = j;
                p->next = t;
                G.AdjList[i].frist = p;
            }
        }
    }
}
void visit_G(ALGraph G)
{
    for (int i = 0; i < G.node_num; i++)
    {
        printf("node:%d data:%3d\tArc:", i, G.AdjList[i].data);
        ArcNode *t = G.AdjList[i].frist;
        while (t)
        {
            printf("<%3d%3d>", i, t->node_num);
            t = t->next;
        }
        printf("\n");
    }
}